<template>
  <div class="element-loading-container" :class="{ overlay: overlay, fullscreen: fullscreen }">
    <el-loading 
      v-model:loading="true"
      :text="text"
      :background="background"
      :spinner="spinner"
      :custom-class="customClass"
    >
      <div class="loading-content">
        <!-- 进度条 -->
        <div v-if="showProgress && progress !== null" class="loading-progress">
          <el-progress 
            :percentage="progress" 
            :stroke-width="6"
            :show-text="true"
            :text-inside="true"
            status="success"
          />
        </div>
      </div>
    </el-loading>
  </div>
</template>

<script setup lang="ts">
import { ElLoading, ElProgress } from 'element-plus'

interface Props {
  // 加载文本
  text?: string
  // 背景色
  background?: string
  // 自定义spinner
  spinner?: string
  // 自定义class
  customClass?: string
  // 是否显示遮罩层
  overlay?: boolean
  // 是否全屏显示
  fullscreen?: boolean
  // 是否显示进度条
  showProgress?: boolean
  // 进度值 (0-100)
  progress?: number | null
}

withDefaults(defineProps<Props>(), {
  text: '加载中...',
  background: 'rgba(255, 255, 255, 0.9)',
  spinner: '',
  customClass: '',
  overlay: false,
  fullscreen: false,
  showProgress: false,
  progress: null
})
</script>

<style scoped>
.element-loading-container {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.element-loading-container.overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(4px);
  z-index: 1000;
}

.element-loading-container.fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  z-index: 9999;
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.loading-progress {
  width: 200px;
  margin-top: 16px;
}

/* 深色主题支持 */
@media (prefers-color-scheme: dark) {
  .element-loading-container.overlay,
  .element-loading-container.fullscreen {
    background: rgba(0, 0, 0, 0.8);
  }
}
</style> 